home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 4_10.lha / 4_10 / main.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  1KB  |  51 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6.  
  7. ouble **mkarray(int rows, int cols);
  8. nt matinv(double **A, double **I, int n);
  9.  
  10. oid prarray(double **a, int rows, int cols, char *name)
  11.  
  12.    cout << "\n\n" << name << "\t(" << rows << " x " << cols << ")\n\n\n";
  13.    for (int i = 0; i < rows; i++)
  14. {
  15. for (int j = 0; j < cols; j++)
  16.     {
  17.     cout << "\t" << a[i][j];
  18.     }
  19. cout << "\n";
  20. }
  21.  
  22.  
  23. oid rdarray(double **a, int rows, int cols)
  24.  
  25.    for (int i = 0; i < rows; i++)
  26.        for (int j = 0; j < cols; j++)
  27.     cin >> a[i][j];
  28.  
  29.  
  30. ain()
  31.  
  32.    int size;
  33.    cin >> size;
  34.    double **A = mkarray(size, size);
  35.    rdarray(A, size, size);
  36.    prarray(A, size, size, "A");
  37.    double **I = mkarray(size, size);
  38.    double **S = mkarray(size, size);
  39.    rdarray(S, size, size);
  40.    int ret = matinv(A, I, size);
  41.    if (ret == 0)
  42.        cout << "singular matrix!\n";
  43.    else
  44.        {
  45. prarray(A, size, size, "A again");
  46. prarray(I, size, size, "inverse");
  47. prarray(S, size, size, "should be");
  48. }
  49.    return 0;
  50.  
  51.